package main

import (
	"github.com/yuin/gopher-lua"
)

func main() {
	l := lua.NewState()
	defer l.Close()
	if err := l.DoString(`print("Hello World")`); err != nil {
		panic(err)
	}
	{
		//L := lua.NewState()
		//defer L.Close()
		//if err := L.DoString(`print("hello")`); err != nil {
		//	panic(err)
		//}
		//lv := L.Get(-1)
		//if str, ok := lv.(lua.LString); ok {
		//	// lv is LString
		//	fmt.Println(string(str))
		//}
		//if lv.Type() != lua.LTString {
		//	panic("string required.")
		//}
	}
	{
		double := func(L *lua.LState) int {
			lv := L.ToInt(1)                 /* get argument */
			l2 := L.ToInt(2)                 /* get argument */
			L.Push(lua.LNumber(lv * 2 * l2)) /* push result */
			L.Push(lua.LNumber(lv * 2 * l2)) /* push result */
			return 1                         /* number of results */
		}
		L := lua.NewState()
		defer L.Close()
		L.SetGlobal("double", L.NewFunction(double))
		if err := L.DoString(`return double(20,60)`); err != nil {
			panic(err)
		}
		get := L.Get(-1)
		println(get.String())
	}
}
